<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.bindings</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_bindings_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Spec - howl.bindings</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.bindings">howl.bindings</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="k">while</span><span class="w"> </span><span class="o">#</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;    </span><span class="n">bindings</span><span class="p">.</span><span class="n">pop</span><span class="o">!</span><span class="w">&#x000A;&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">cancel_capture</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="push">push<span class="arg-list">(map, options = {})</span></h2>&#x000A;&#x000A;<h4 id="pushes-&lt;map&gt;-to-the-keymap-stack-at-.keymaps">pushes &lt;map&gt; to the keymap stack at .keymaps</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">map</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">map</span><span class="p">,</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">[</span><span class="o">#</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">]</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="pop">pop<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="pops-the-top-most-keymap-of-the-stack-at-.keymaps">pops the top-most keymap of the stack at .keymaps</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">stack_before</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">moon</span><span class="p">.</span><span class="n">copy</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">pop</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">stack_before</span><span class="p">,</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="remove">remove<span class="arg-list">(map)</span></h2>&#x000A;&#x000A;<h4 id="removes-the-specified-map-from-the-keymap-stack">removes the specified map from the keymap stack</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">stack</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">moon</span><span class="p">.</span><span class="n">copy</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w">&#x000A;</span><span class="n">m1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">m2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">m1</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">m2</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">remove</span><span class="w"> </span><span class="n">m1</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">stack</span><span class="p">,</span><span class="w"> </span><span class="n">m2</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">stack</span><span class="p">,</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="translate_key">translate_key<span class="arg-list">(event)</span></h2>&#x000A;&#x000A;<h4 id="adds-special-case-translations-for-certain-common-keys">adds special case translations for certain common keys</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">for_keynames</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="ss">kp_up:</span><span class="w"> </span><span class="s1">'up'</span><span class="w">&#x000A;  </span><span class="ss">kp_down:</span><span class="w"> </span><span class="s1">'down'</span><span class="w">&#x000A;  </span><span class="ss">kp_left:</span><span class="w"> </span><span class="s1">'left'</span><span class="w">&#x000A;  </span><span class="ss">kp_right:</span><span class="w"> </span><span class="s1">'right'</span><span class="w">&#x000A;  </span><span class="ss">kp_page_up:</span><span class="w"> </span><span class="s1">'page_up'</span><span class="w">&#x000A;  </span><span class="ss">kp_page_down:</span><span class="w"> </span><span class="s1">'page_down'</span><span class="w">&#x000A;  </span><span class="ss">iso_left_tab:</span><span class="w"> </span><span class="s1">'tab'</span><span class="w"> </span><span class="c1">-- shifts are automatically prepended</span><span class="w">&#x000A;  </span><span class="ss">return:</span><span class="w"> </span><span class="s1">'enter'</span><span class="w">&#x000A;  </span><span class="ss">altL:</span><span class="w"> </span><span class="s1">'alt'</span><span class="w">&#x000A;  </span><span class="ss">altR:</span><span class="w"> </span><span class="s1">'alt'</span><span class="w">&#x000A;  </span><span class="ss">shiftL:</span><span class="w"> </span><span class="s1">'shift'</span><span class="w">&#x000A;  </span><span class="ss">shiftR:</span><span class="w"> </span><span class="s1">'shift'</span><span class="w">&#x000A;  </span><span class="ss">ctrlL:</span><span class="w"> </span><span class="s1">'ctrl'</span><span class="w">&#x000A;  </span><span class="ss">ctrlR:</span><span class="w"> </span><span class="s1">'ctrl'</span><span class="w">&#x000A; </span><span class="p">}</span><span class="w">&#x000A;&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">alternative</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">for_keynames</span><span class="w">&#x000A;  </span><span class="n">translations</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="n">name</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">includes</span><span class="w"> </span><span class="n">translations</span><span class="p">,</span><span class="w"> </span><span class="n">alternative</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="substitutes-certain-key-names-to-prevent-ambiguity">substitutes certain key names to prevent ambiguity</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">for_keynames</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="ss">alt_l:</span><span class="w"> </span><span class="s1">'altL'</span><span class="w">&#x000A;  </span><span class="ss">alt_r:</span><span class="w"> </span><span class="s1">'altR'</span><span class="w">&#x000A;  </span><span class="ss">shift_l:</span><span class="w"> </span><span class="s1">'shiftL'</span><span class="w">&#x000A;  </span><span class="ss">shift_r:</span><span class="w"> </span><span class="s1">'shiftR'</span><span class="w">&#x000A;  </span><span class="ss">control_l:</span><span class="w"> </span><span class="s1">'ctrlL'</span><span class="w">&#x000A;  </span><span class="ss">control_r:</span><span class="w"> </span><span class="s1">'ctrlR'</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">substitution</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">for_keynames</span><span class="w">&#x000A;  </span><span class="n">translations</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="n">name</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">includes</span><span class="w"> </span><span class="n">translations</span><span class="p">,</span><span class="w"> </span><span class="n">substitution</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_includes</span><span class="w"> </span><span class="n">translations</span><span class="p">,</span><span class="w"> </span><span class="n">name</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(for ordinary characters)</span></h3>&#x000A;&#x000A;<h4 id="returns-a-table-with-the-character,-key-name-and-key-code-string">returns a table with the character, key name and key code string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="skips-the-translation-for-key-name-if-it-is-the-same-as-for-character">skips the translation for key name if it is the same as for character</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when character is missing)</span></h3>&#x000A;&#x000A;<h4 id="returns-a-table-with-key-name-and-key-code-string">returns a table with key name and key code string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'down'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'down'</span><span class="p">,</span><span class="w"> </span><span class="s1">'123'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when only the code is available)</span></h3>&#x000A;&#x000A;<h4 id="returns-a-table-with-the-key-code-string">returns a table with the key code string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'123'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(with modifiers)</span></h3>&#x000A;&#x000A;<h4 id="prepends-a-modifier-string-representation-to-all-translations-for-ctrl-and-alt">prepends a modifier string representation to all translations for ctrl and alt</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w">&#x000A;  </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="ss">control:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">alt:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">mods</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ctrl_alt_'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">mods</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="n">mods</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="n">mods</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'123'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="emits-the-shift-modifier-if-the-character-is-known">emits the shift modifier if the character is known</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">tr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">translate_key</span><span class="w">&#x000A;  </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="ss">control:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">shift:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">tr</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'ctrl_A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ctrl_shift_a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ctrl_shift_123'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="process">process<span class="arg-list">(event, source, extra_keymaps, ..)</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when firing the key-press signal)</span></h3>&#x000A;&#x000A;<h4 id="passes-the-event,-translations,-source-and-parameters">passes the event, translations, source and parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">event</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;&#x000A;</span><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'key-press'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="p">,</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="s1">'yowser'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;    </span><span class="ss">:event</span><span class="w">&#x000A;    </span><span class="ss">source:</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;    </span><span class="ss">translations:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;    </span><span class="ss">parameters:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'yowser'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-early-with-true-if-the-handler-does">returns early with true if the handler does</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">A</span><span class="p">:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'key-press'</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">keymap</span><span class="p">.</span><span class="n">A</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">not_called</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">ret</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="continues-processing-keymaps-if-the-handler-returns-false">continues processing keymaps if the handler returns false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">A</span><span class="p">:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'key-press'</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">keymap</span><span class="p">.</span><span class="n">A</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when looking up handlers)</span></h3>&#x000A;&#x000A;<h4 id="tries-each-translated-key-and-.on_unhandled-in-order-for-a-keymap,-and-optional-source-specific-map">tries each translated key and .on_unhandled in order for a keymap, and optional source specific map</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'my_source'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'my_source'</span><span class="p">,</span><span class="w"> </span><span class="s1">'binding_for'</span><span class="p">,</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="p">,</span><span class="w"> </span><span class="s1">'on_unhandled'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">keymap</span><span class="p">.</span><span class="n">reads</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="prefers-source-specific-bindings">prefers source specific bindings</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">specific_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">A</span><span class="p">:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">general_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="nc">A</span><span class="p">:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="ss">my_source:</span><span class="w"> </span><span class="n">specific_map</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'my_source'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">general_map</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">specific_map</span><span class="p">.</span><span class="n">A</span><span class="p">).</span><span class="n">was_called</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">general_map</span><span class="p">.</span><span class="n">A</span><span class="p">).</span><span class="n">was_not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="searches-all-extra-keymaps-and-the-bindings-in-the-stack">searches all extra keymaps and the bindings in the stack</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">key_args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">extra_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">stack_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">stack_map</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">key_args</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">extra_map</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">stack_map</span><span class="p">.</span><span class="n">reads</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">stack_map</span><span class="p">.</span><span class="n">reads</span><span class="p">,</span><span class="w"> </span><span class="n">extra_map</span><span class="p">.</span><span class="n">reads</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when .on_unhandled is defined and keys are not found in a keymap)</span></h3>&#x000A;&#x000A;<h4 id="is-called-with-the-event,-source,-translations-and-extra-parameters">is called with the event, source, translations and extra parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">on_unhandled:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">event</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">keymap</span><span class="p">},</span><span class="w"> </span><span class="s1">'hello!'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">keymap</span><span class="p">.</span><span class="n">on_unhandled</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="p">(</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'hello!'</span><span class="p">)</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="any-return-is-used-as-the-handler">any return is used as the handler</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">on_unhandled:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">handler</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when .binding_for is defined and keys are not found in a keymap)</span></h3>&#x000A;&#x000A;<h4 id="is-looked-up-by-keys-bound-to-the-commands-in-.binding_for">is looked up by keys bound to the commands in .binding_for</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">a:</span><span class="w"> </span><span class="s1">'my-command'</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">binding_for:</span><span class="w"> </span><span class="p">[</span><span class="s1">'my-command'</span><span class="p">]:</span><span class="w"> </span><span class="n">handler</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="ss">character:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">97</span><span class="p">},</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when a keymap was pushed with options.block set to true)</span></h3>&#x000A;&#x000A;<h4 id="looks-no-further-down-the-stack-than-that-keymap">looks no further down the stack than that keymap</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">base</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">blocking</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">base</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">blocking</span><span class="p">,</span><span class="w"> </span><span class="ss">block:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">base</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when a keymap was pushed with options.pop set to true)</span></h3>&#x000A;&#x000A;<h4 id="is-automatically-popped-after-the-next-dispatch">is automatically popped after the next dispatch</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">pop_me</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">pop_me</span><span class="p">,</span><span class="w"> </span><span class="ss">pop:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">pop_me</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_includes</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">,</span><span class="w"> </span><span class="n">pop_me</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="is-popped-regardless-of-whether-it-contained-a-matching-binding-or-not">is popped regardless of whether it contained a matching binding or not</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">pop_me</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">pop_me</span><span class="p">,</span><span class="w"> </span><span class="ss">pop:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_includes</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">,</span><span class="w"> </span><span class="n">pop_me</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="is-always-blocking">is always blocking</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">base</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">pop_me</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">base</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="n">pop_me</span><span class="p">,</span><span class="w"> </span><span class="ss">pop:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">pop_me</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">base</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when invoking handlers)</span></h3>&#x000A;&#x000A;<h4 id="invokes-handlers-in-their-own-coroutines">invokes handlers in their own coroutines</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">coros</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">coro_register</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">co</span><span class="p">,</span><span class="w"> </span><span class="n">main</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">coroutine.running</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">coros</span><span class="p">[</span><span class="n">co</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">main</span><span class="w">&#x000A;&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">coro_register</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="p">[</span><span class="n">v</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">coros</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-false-if-no-handlers-are-found">returns false if no handlers are found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="invokes-handlers-in-extra-keymaps-before-the-default-keymap">invokes handlers in extra keymaps before the default keymap</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">bindings</span><span class="p">.</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">extra_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">extra_map</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">extra_map</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_called</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymap</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was_not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when the handler is callable)</span></h3>&#x000A;&#x000A;<h4 id="passes-along-any-extra-arguments">passes along any extra arguments</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'reference'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">keymap</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="p">(</span><span class="s1">'reference'</span><span class="p">)</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-early-with-true-unless-a-handler-explicitly-returns-false">returns early with true unless a handler explicitly returns false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">first</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">second</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'space'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">first</span><span class="p">,</span><span class="w"> </span><span class="n">second</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">second</span><span class="p">.</span><span class="n">k</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-5">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when the handler raises an error)</span></h3>&#x000A;&#x000A;<h4 id="returns-true">returns true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nb">error</span><span class="w"> </span><span class="s1">'BOOM!'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'mybad'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="logs-an-error-to-the-log">logs an error to the log</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nb">error</span><span class="w"> </span><span class="s1">'a to the k log'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'mybad'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">[</span><span class="o">#</span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">].</span><span class="n">message</span><span class="p">,</span><span class="w"> </span><span class="s1">'a to the k log'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when the handler is a string)</span></h3>&#x000A;&#x000A;<h4 id="runs-the-command-with-command.run()-and-returns-true">runs the command with command.run() and returns true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">cmd_run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">on</span><span class="p">(</span><span class="n">command</span><span class="p">,</span><span class="w"> </span><span class="s1">'run'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="s1">'spy'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">command</span><span class="p">.</span><span class="n">run</span><span class="o">\</span><span class="n">revert</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">cmd_run</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="s1">'spy'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when the handler is a non-callable table)</span></h3>&#x000A;&#x000A;<h4 id="pushes-the-table-as-a-new-keymap-and-returns-true">pushes the table as a new keymap and returns true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">nr_bindings</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">#</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w">&#x000A;</span><span class="n">submap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">submap</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">nr_bindings</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">submap</span><span class="p">,</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">[</span><span class="o">#</span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="pushes-the-table-with-the-pop-option">pushes the table with the pop option</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">submap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">k:</span><span class="w"> </span><span class="n">submap</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'k'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_includes</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="p">,</span><span class="w"> </span><span class="n">submap</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="capture">capture<span class="arg-list">(function)</span></h2>&#x000A;&#x000A;<h4 id="causes-&lt;function&gt;-to-be-called-exclusively-with-event,-source,-translations-and-any-extra-parameters">causes &lt;function&gt; to be called exclusively with event, source, translations and any extra parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">event</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">thief</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">keymap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">A</span><span class="p">:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">capture</span><span class="w"> </span><span class="n">thief</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'source'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">keymap</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'catch-me!'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">keymap</span><span class="p">.</span><span class="n">A</span><span class="p">).</span><span class="n">was_not</span><span class="p">.</span><span class="n">called</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">thief</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="p">(</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'source'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'65'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'catch-me!'</span><span class="p">)</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="&lt;function&gt;-continues-to-capture-events-as-long-as-it-returns-false">&lt;function&gt; continues to capture events as long as it returns false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">event</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w">&#x000A;</span><span class="n">thief</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">ret</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">capture</span><span class="w"> </span><span class="n">thief</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">thief</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="cancel_capture">cancel_capture<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="cancels-any-currently-set-capture">cancels any currently set capture</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">thief</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">ret</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">capture</span><span class="w"> </span><span class="n">thief</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">cancel_capture</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">thief</span><span class="p">).</span><span class="n">was_not</span><span class="p">.</span><span class="n">called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".is_capturing">.is_capturing</h2>&#x000A;&#x000A;<h4 id="is-true-when-a-capture-is-active-and-false-otherwise">is true when a capture is active and false otherwise</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">is_capturing</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">capture</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">is_capturing</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">process</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">character:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_name:</span><span class="w"> </span><span class="s1">'A'</span><span class="p">,</span><span class="w"> </span><span class="ss">key_code:</span><span class="w"> </span><span class="mi">65</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'editor'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">is_capturing</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="keystrokes_for">keystrokes_for<span class="arg-list">(handler, source)</span></h2>&#x000A;&#x000A;<h4 id="returns-all-the-key-bindings-that-maps-to-&lt;handler&gt;">returns all the key bindings that maps to &lt;handler&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">ctrl_y:</span><span class="w"> </span><span class="s1">'my-command'</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">ctrl_x:</span><span class="w"> </span><span class="s1">'my-command'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="s1">'ctrl_x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ctrl_y'</span><span class="p">},</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keystrokes_for</span><span class="w"> </span><span class="s1">'my-command'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-an-empty-table-if-no-binding-was-found">returns an empty table if no binding was found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keystrokes_for</span><span class="w"> </span><span class="s1">'my-command'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="action_for">action_for<span class="arg-list">(translation)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">saved_keymaps</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">saved_keymaps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bindings</span><span class="p">.</span><span class="n">keymaps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">saved_keymaps</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-the-command-bound-to-translation">returns the command bound to translation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">ctrl_x:</span><span class="w"> </span><span class="s1">'my-old-command'</span><span class="w">&#x000A;</span><span class="n">bindings</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">ctrl_x:</span><span class="w"> </span><span class="s1">'my-new-command'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'my-new-command'</span><span class="p">,</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">action_for</span><span class="w"> </span><span class="s1">'ctrl_x'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-nil-if-no-command-was-found">returns nil if no command was found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">bindings</span><span class="p">.</span><span class="n">action_for</span><span class="w"> </span><span class="s1">'ctrl_x'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
